﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Xf.MvcTag.UIExt.DataTables
{
    public class DtResult
    {
        public int Draw { get; set; }
        public int RecordsTotal { get; set; }
        public int RecordsFiltered { get; set; }
        public static DtResult<T> Page<T>(DtRequest dtRequest, List<T> data) where T : class
        {
            DtResult<T> dtResult = new DtResult<T>();
            dtResult.Draw = dtRequest.Draw;
            dtResult.RecordsTotal = data.Count;
            dtResult.RecordsFiltered = data.Count;
            dtResult.Data = data;
            return dtResult;
        }
        public static DtResult<T> Page<T>(DtRequest request,IQueryable<T> queryable)
        {
            DtResult<T> dtResult = new DtResult<T>();
            dtResult.Draw = request.Draw;
            dtResult.RecordsTotal = queryable.Count();
            dtResult.RecordsFiltered = dtResult.RecordsTotal;
            dtResult.Data = queryable.Skip(request.Start).Take(request.Length).ToList();
            return dtResult;
        }
    }

    public class DtResult<T> : DtResult 
    {
        public IEnumerable<T> Data { get; set; }
    }

}
